<?php
namespace app\admin\controller;

use think\captcha\Captcha;

class Site extends Base
{
    public function login()
    {
        if(request()->isPost()){

            $username=i("username","用户名不能为空");
            $password=input("password");

            $admin = model("admin")->where("username",$username)->where("password",$password)->find();
            if(empty($admin)){
                $this->error("账号或者密码不正确");
            }
            session("admin",$admin);
            $this->redirect("/admin");
            return;
        }
        return view();
    }
    public function update(){
        $this->getsite();
        $this->assign("info",c("site"));
        if(request()->isPost()){
            $site=c("site");
            $username=input("username");
            $password=input("password");
            if($username!=""){
                $site['username']=$username;
            }
            if($password!="" && $password!="******"){
                $site['password']=$password;
            }
            c("site",$site);
            session("site",null);
            echo "<script>parent.window.location.href='/admin/user/login'</script>";
            exit();

        }
        return view();
    }

    public function set(){
        $this->getsite();
        if(request()->isPost()){

            $data = $this->autodata();
            
            c("info",$data);
            $this->success('编辑程功');
        }
        $info=c("info");
        $this->assign('info',$info);
        return view();
    }
    public function logout(){
        session("admin",null);
        $this->redirect("/admin/site/login");
    }
}
